package com.java.netty.websocket;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @author jiangli
 * @date 2019/10/29 21:52
 */
public class WSServer {

	public static void main(String[] args) throws Exception{
		//设置线程组
		EventLoopGroup masterGroup = new NioEventLoopGroup();
		EventLoopGroup workerGroup = new NioEventLoopGroup();

		try {
			ServerBootstrap serverBootstrap = new ServerBootstrap();
			serverBootstrap.group(masterGroup,workerGroup)
					.channel(NioServerSocketChannel.class)
					.childHandler(new WSServerInitializer());

			//设置端口和同步启动
			ChannelFuture future = serverBootstrap.bind(8088).sync();
			//监听channel关闭
			future.channel().closeFuture().sync();
		} finally {
			//优雅的关闭
			masterGroup.shutdownGracefully();
			workerGroup.shutdownGracefully();
		}

	}
}
